Efficient detection of texture sharing between multiple contexts

ABSTRACT

A technique for detecting texture sharing between multiple contexts having unique ID&#39;s includes obtaining a texture usage mask of a subject texture and a context ID of a subject context. A first logic operation with the texture usage mask of the subject texture and the context ID of the subject context is performed to produce a resultant value. The subject texture is determined not to be shared by another context with the subject context upon the resultant value being equal to a first predetermined value. The subject texture is determined to be shared by another context with the subject context upon the resultant value being equal to a second predetermined value which is different from the first predetermined value. The texture usage mask of a subject texture may be revised prior to the subject texture being used by another context by performing a second logic operation with the texture usage mask and a context ID of another context to produce a resultant new texture usage mask for the subject texture. The texture usage mask of a subject texture may be revised upon the subject texture no longer being used by a particular context by performing a third logic operation with the texture usage mask and a context ID of the particular context to produce a resultant new texture usage mask for the subject texture.

FIELD

The present invention relates to texture sharing in an openGL API(Application Programming Interface) or other graphics programminginterface. More particularly, the present invention relates to atechnique for effecting an efficient detection of texture sharingbetween multiple contexts.

BACKGROUND

Graphics programming interfaces, such as the openGL API, are beingrapidly developed to keep up with their great demand for use in graphicsdisplays in computer applications. U.S. Pat. No. 5,818,469, to JohnJoseph Lawless et al. discloses an example of a graphics programminginterface.

FIG. 1, which illustrates a schematic representation of a graphicsarchitecture shows a graphics application 101 which is typically runningon a workstation or other computer system. A graphics interface 103receives data from the graphics application 101 and processes the dataprior to forwarding it to hardware 115 using a plurality of threads. Athread is a predefined program segment and is operable to effect theaccomplishment of a specified individual graphics task such asrasterizing or rendering. A plurality of threads 107 and 109 to be usedfor rendering are fed from the graphic interface 103 to the hardware115. Each thread maintains its own local graphics context containing theattribute state. Threads 107 and 109 may include related graphicscontexts 108 and 110, respectively associated therewith.

FIG. 2, which illustrates a simplified block diagram of a computersystem, shows an exemplary system 200 in which the graphics subsystem217 corresponds to the hardware 115 of FIG. 1. A central processing unit(CPU) 201 is connected to a central bus 203. A memory subsystem 205 andcache memory 207 are also connected to the bus 203 as is a storage block215 which may include one or more storage devices such as floppy diskdrives, hard drives, etc. A display device 219 is connected to thegraphics subsystem 217. An input interface device 209 connects akeyboard 211 and a mouse 213 to the bus 203. The bus 203 may be extended221 to be connected to other systems and/or devices.

The graphics subsystem 217 typically includes an internal graphicsprocessor as well as a frame buffer memory for use in connection withthe display device. For example, the graphics subsystem 217 generallyincludes rasterization hardware as well as other specific graphicsengines. Instructions for performing graphics interfacing processes maybe executed by the processor 201 and/or a separate graphics processordisposed within the graphics subsystem 217. To such instructions may beembodied within or stored in any one of or a combination of storagedevices and/or memory devices including RAM memory within the memorysubsystem 205, any of the storage elements of the storage block 215 orany portable storage device, such as a floppy disk or CD.

The openGL API provides for textures to be shared by multiple renderingcontexts. In addition, each context may have multiple texture units thatuse the same texture. For certain operations with a texture, it isimportant to distinguish between multiple contexts using a texture or asingle context using a texture in multiple units.

BRIEF DESCRIPTION OF THE DRAWINGS

The foregoing and a better understanding of the present invention willbecome apparent from the following detailed description of exampleembodiments and the claims when read in connection with the accompanyingdrawings, all forming a part of the disclosure of this invention. Whilethe foregoing and following written and illustrated disclosure focuseson disclosing example embodiments of the invention, it should be clearlyunderstood that the same is by way of illustration and example only andthe invention is not limited thereto. The spirit and scope of thepresent invention is limited only by the terms of the appended claims.

The following represents brief descriptions of the drawings, wherein:

FIG. 1 illustrates a schematic representation of a graphics architecturearrangement.

FIG. 2 illustrates a simplified block diagram of a computer system.

FIG. 3 illustrates an example used for explaining the technique inaccordance with the present invention.

FIG. 4 illustrates a flowchart used for explaining the technique inaccordance with the present invention.

DETAILED DESCRIPTION

Before beginning a detailed description of the subject invention,mention of the following is in order. When appropriate, like referencenumerals and characters may be used to designate identical,corresponding, or similar components in differing drawing figures.Furthermore, in the detailed description to follow, examplesizes/models/values/ranges may be given, although the present inventionis not limited thereto. In addition, various connections and otherelements may not be shown within the drawing figures for simplicity ofillustration and discussion and so as not to obscure the invention.

The openGL API, as with other graphics APIs, provides for a renderingcontext. The rendering context encapsulates all of the states necessaryto render triangles with attributes such as color, fog, etc. The contextinformation also includes texture images that may consume large amountsof memory. OpenGL allows an application to have multiple contexts sothat the separate context can be bound to multiple threads to allowsimultaneous rendering by multiple threads. However, one context can bebound to only one thread. Since the texture images are fairly large,openGL allows for sharing of textures by multiple contexts. When thingsare shared between multiple threads, it is a common practice to includemutual exclusion locks to prevent a second thread from using the sametexture object while the first thread is using the texture object.However, in order to avoid a stall of any thread for a substantial timeperiod, the mutual exclusion lock may be used only for a short timeperiod to set a read lock flag in the texture and then release themutual exclusion lock. The read lock flag could be implemented by simplyupdating a reference counter of the texture. This allows both thethreads to simultaneously render using the same texture.

Due to recent advances in graphics hardware, openGL, for example, allowsfor each context to have multiple texture units. The result of ablending of a polygon color and a lookup from one texture unit arepassed onto the next texture unit. A single texture may be assigned tomultiple units in a multi-texture pipeline.

An application may request the driver to change the texture image or anyof its attributes. In order to safely change the texture image on onethread, it is important to know whether the texture is being used byonly this thread/context or is being used by multiple threads/contexts.If each openGL context supported only one texture unit and if a texturehad a reference count of more than 1, then there would be an implicationthat the texture is being used by multiple contexts and could not besafely modified. However, due to the presence of multiple texture units,a reference count does not provide all the information. For example, areference count of 2 may indicate one of two alternatives, namely,either a texture is being used by a single texture unit on multiplecontexts or is being used by multiple texture units on a single context.If the texture was being used by a single context on multiple textureunits, then the texture could be safely modified but if the texture wasused by multiple contexts then the texture could not safely be modified.

In order to determine whether a texture is being used by only a singlecontext, it is possible to compare the texture with all of the textureunits on a context and determine a usage count for a context. If theusage count matched the reference count for the texture, it would implythat the texture was being used only on this context. The determinationof the usage count requires one compare operation and potentially oneaddition operation per texture unit. With the rapid improvements ingraphics hardware, there is a reasonable expectation that the number oftexture units may increase to 32 texture units. Thus, this method ofdetermining the usage of a texture becomes rather expensive whenapplications require fast state changes for optimal performance.

In the present invention, when contexts request the sharing of a set oftextures, each context is provided with its own unique identifier (ID).This unique identifier is a single bit in an integer word. When acontext starts using a texture, it bitwise ORs its unique context IDinto a texture usage mask. Each texture has its own texture usage mask.This texture usage mask tracks the identifiers of all of the contextsusing the corresponding texture. If only one bit is turned on in thetexture usage mask, then only one context is using the texture.Accordingly, to determine whether a texture is being used by anothercontext, only the following simple test need be performed.

If the texture usage mask ANDed with the inverted context ID is equal to0, then the texture is not being used by another context. If the textureusage mask ANDed with the inverted context ID is not equal to 0, thenthe texture is being used by another context.

FIG. 3 illustrates an example used for explaining the technique inaccordance with the present invention. As illustrated in FIG. 3, thereare two contexts, Context 1 and Context 2, each context having 4 textureunits. Texture A is being used by both Context 1 and Context 2 whileTexture B is being used in multiple units only on Context 1. As can beseen from FIG. 3, Texture A has a reference count of 2. Furthermore, thetexture usage mask for the texture, which is obtained by bitwise ORingof the two context IDs, indicates that both contexts are using thetexture. On the other hand, Texture B, which also has a reference countof 2, only has the context ID bit for Context 1 set in its texture usagemask, thereby indicating that only a single context is using thetexture. Thus, while the share status of a texture cannot be determinedby the reference count of a texture, the texture usage mask for atexture clearly indicates whether the texture is being used by a singlecontext or by multiple contexts. With the present invention, thedetermination of texture usage for multiple contexts can be effectedusing only one invert operation and one compare operation. In fact, theinvert operation may be eliminated by maintaining a precomputed invertedcontext ID for each context.

FIG. 4 illustrates a flowchart used for explaining the technique inaccordance with a present invention. Upon starting the technique fordetecting the sharing of a texture between multiple contexts, in block410, the texture usage mask of a subject texture is obtained.

In block 420, the context ID of a subject context is obtained and inblock 430, a first logic operation is performed to produce a resultantvalue. As noted above, for example, the first logic operation might bethe ANDing of the texture usage mask of the subject texture with aninverted context ID of the subject context to produce the resultantvalue.

In block 440, a determination is made as to whether the resultant valueis equal to a first or second predetermined value. If the resultantvalue is equal to the first predetermined value, then the subjecttexture is not being shared while if the resultant value is equal to thesecond predetermined value, then the subject texture is being shared. Asnoted above, for example, the first predetermined value may be equal to0 while the second predetermined value may be equal to any value otherthan 0.

When a context stops using a texture, it's context ID bit in thecorresponding texture usage mask must be reset. This is performed asfollows:

-   -   1. For the texture which is no longer going to be used, clear        the context ID bit in its texture usage mask.    -   2. Attach a new texture to the texture unit.    -   3. Loop over all of the texture units in a context.

For each texture, set the context ID bit for this context in itscorresponding texture usage mask.

The above-noted operation performs as many bitwise OR operations as thenumber of texture units. Note that multiple compare operationsassociated with the reference count scheme have been eliminated. Indeeply pipelined hardware CPU implementations, compare operations may becomputationally very expensive. In addition, the operation is performedonly when a unit stops using a texture. The normal mode for a textureunit is to attach a texture, perform multiple operations on the texture,and then stop using the texture. Thus, with the present invention,operations that are proportional to the number of texture units areperformed only once when a texture is detached from a texture unit.

In addition to modifying a texture, an openGL engine, for example, issupposed to virtualize textures. That is, if a system does not haveenough hardware texture memory, then the driver is supposed to swap outsome textures to the system memory and page in other textures from thesystem memory to the hardware texture memory. The texture manager, whenexecuting one thread, must insure that it does not page out a texturethat is actively being used by another texture unit. This can easily bedetermined by using the unique context IDs and the texture usage masksof the present invention rather than using a reference count which doesnot provide a complete answer.

Compared to existing techniques, the present invention reduces thenumber of operations from being on the order of the number of textureunits to just one operation most of the time. Even when the number ofoperations is proportional to the number of texture units, the techniquein accordance with the present invention is faster due to theelimination of costly compare operations.

This concludes the description of the example embodiments. Although thepresent invention has been described with reference to illustrativeembodiments, it is to be understood that numerous other modificationsand embodiments can be devised by those skilled in the art that willfall within the spirit and scope of the principles of this invention.More particularly, reasonable variations and modifications are possiblein the component parts and/or arrangements of the subject combinationarrangement within the scope of the foregoing disclosure, the drawings,and the appended claims without departing from the spirit of theinvention. In addition to variations and modifications in the componentparts and/or arrangements, alternative uses will be apparent to thoseskilled in the art.

1. A method of detecting texture sharing between multiple contextshaving unique context ID's: obtaining a texture usage mask of a subjecttexture; obtaining an inverted context ID of a subject context; ANDingthe texture usage mask of the subject texture with the inverted contextID of the subject context to produce a resultant value; and detectingthat the subject texture is not being shared by another context with thesubject context upon the resultant value being equal to 0 and detectingthat the subject texture is being shared by another context with thesubject context upon the resultant value not being equal to
 0. 2. Themethod of claim 1, further comprising: revising the texture usage maskof a subject texture prior to the subject texture being used by anothercontext by bitwise ORing the texture usage mask with a context ID of theanother context to produce a resultant new texture usage mask for thesubject texture.
 3. The method of claim 1, further comprising: revisingthe texture usage mask of a subject texture upon the subject texture nolonger being used by a particular context by deleting a context ID ofthe particular context from the texture usage mask to produce aresultant new texture usage mask for the subject texture.
 4. The methodof claim 2, further comprising: revising the texture usage mask of asubject texture upon the subject texture no longer being used by aparticular context by deleting a context ID of the particular contextfrom the texture usage mask to produce a resultant new texture usagemask for the subject texture.
 5. A method of detecting texture sharingbetween multiple contexts having unique context ID's: obtaining atexture usage mask of a subject texture; obtaining a context ID of asubject context; performing a first logic operation with the textureusage mask of the subject texture and the context ID of the subjectcontext to produce a resultant value; and detecting that the subjecttexture is not being shared by another context with the subject contextupon the resultant value being equal to a first predetermined value anddetecting that the subject texture is being shared by another contextupon the resultant value being equal to a second predetermined valuewhich is different from the first predetermined value.
 6. The method ofclaim 5, further comprising: revising the texture usage mask of asubject texture prior to the subject texture being used by anothercontext by performing a second logic operation with the texture usagemask and a context ID of the another context to produce a resultant newtexture usage mask for the subject texture.
 7. The method of claim 5,further comprising: revising the texture usage mask of a subject textureupon the subject texture no longer being used by a particular context byperforming a third logic operation with the texture usage mask and acontext ID of the particular context to produce a resultant new textureusage mask for the subject texture.
 8. The method of claim 7, furthercomprising: revising the texture usage mask of a subject texture uponthe subject texture no longer being used by a particular context byperforming a third logic operation with the texture usage mask and acontext ID of the particular context to produce a resultant new textureusage mask for the subject texture.
 9. A program storage device readableby a machine, tangibly embodying a program of instructions executable bythe machine to perform a method of detecting texture sharing betweenmultiple contexts having unique context ID's, the method comprising:obtaining a texture usage mask of a subject texture; obtaining aninverted context ID of a subject context; ANDing the texture usage maskof the subject texture with the inverted context ID of the subjectcontext to produce a resultant value; and detecting that the subjecttexture is not being shared by another context with the subject contextupon the resultant value being equal to 0 and detecting that the subjecttexture is being shared by another context with the subject context uponthe resultant value not being equal to
 0. 10. The program storage deviceof claim 9, the method further comprising: revising the texture usagemask of a subject texture prior to the subject texture being used byanother context by bitwise ORing the texture usage mask with a contextID of the another context to produce a resultant new texture usage maskfor the subject texture.
 11. The program storage device of claim 9, themethod further comprising: revising the texture usage mask of a subjecttexture upon the subject texture no longer being used by a particularcontext by deleting a context ID of the particular context from thetexture usage mask to produce a resultant new texture usage mask for thesubject texture.
 12. The program storage device of claim 11, the methodfurther comprising: revising the texture usage mask of a subject textureupon the subject texture no longer being used by a particular context bydeleting a context ID of the particular context from the texture usagemask to produce a resultant new texture usage mask for the subjecttexture.
 13. A program storage device readable by a machine, tangiblyembodying a program of instructions executable by the machine to performa method of detecting texture sharing between multiple contexts havingunique context ID's, the method comprising: obtaining a texture usagemask of a subject texture; obtaining a context ID of a subject context;performing a first logic operation with the texture usage mask of thesubject texture and the context ID of the subject context to produce aresultant value; and detecting that the subject texture is not beingshared by another context with the subject context upon the resultantvalue being equal to a first predetermined value and detecting that thesubject texture is being shared by another context upon the resultantvalue being equal to a second predetermined value which is differentfrom the first predetermined value.
 14. The program storage device ofclaim 13, the method further comprising: revising the texture usage maskof a subject texture prior to the subject texture being used by anothercontext by performing a second logic operation with the texture usagemask and a context ID of the another context to produce a resultant newtexture usage mask for the subject texture.
 15. The program storagedevice of claim 13, the method further comprising: revising the textureusage mask of a subject texture upon the subject texture no longer beingused by a particular context by performing a third logic operation withthe texture usage mask and a context ID of the particular context toproduce a resultant new texture usage mask for the subject texture. 16.The program storage device of claim 15, the method further comprising:revising the texture usage mask of a subject texture upon the subjecttexture no longer being used by a particular context by performing athird logic operation with the texture usage mask and a context ID ofthe particular context to produce a resultant new texture usage mask forthe subject texture.